package com.db.beboy;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Schema;

public class BeBoyCache {

    //  辅助文件生成相对路径
    public static final String DAO_PATH = "../app/src/main/cache-gen";
    //辅助文件包名
    public static final String PACKAGE_NAME = "com.eightbears.greendao";
    public static final int DATA_VERSION_CODE = 29;

    public static void main(String[] args) throws Exception {
        Schema schema = new Schema(DATA_VERSION_CODE, PACKAGE_NAME);
        district(schema, "District");
        postSearch(schema, "SearchKey");
        friends(schema, "Friends");
        myAddress(schema, "MyAddress");
        topUser(schema, "TopEaseUser");
        messageStatus(schema, "MessageStatus");
        group(schema, "GroupList");
        groupMember(schema, "GroupMember");
        member(schema, "Member");
        //生成Dao文件路径
        new DaoGenerator().generateAll(schema, DAO_PATH);
    }

    private static void district(Schema schema, String tableName) {
        Entity district = schema.addEntity(tableName);
        district.addStringProperty("id");
        district.addStringProperty("parent_id");
        district.addStringProperty("name");
        district.addStringProperty("type");
        district.implementsSerializable();
    }

    /**
     * 帖子搜索
     */
    private static void postSearch(Schema schema, String tableName) {
        Entity postSearch = schema.addEntity(tableName);
        postSearch.addStringProperty("type");
        postSearch.addStringProperty("search_title");
        postSearch.implementsSerializable();
    }

    /**
     * 好友列表
     */
    private static void friends(Schema schema, String tableName) {
        Entity friends = schema.addEntity(tableName);
        friends.addStringProperty("user_id");
        friends.addStringProperty("nickname");
        friends.addStringProperty("email");
        friends.addStringProperty("cover");
        friends.addStringProperty("status");
        friends.addStringProperty("is_auth");
        friends.addStringProperty("birthday");
        friends.addStringProperty("true_name");
        friends.addStringProperty("sign");
        friends.addStringProperty("sex");
        friends.addStringProperty("mobile");
        friends.addStringProperty("vip_level");
        friends.addStringProperty("unique_id");
        friends.implementsSerializable();
    }

    /**
     * 收货地址
     */
    private static void myAddress(Schema schema, String tableName) {
        Entity myAddress = schema.addEntity(tableName);
        myAddress.addStringProperty("myAddressId");
        myAddress.addStringProperty("name");
        myAddress.addStringProperty("phone");
        myAddress.addStringProperty("address");
        myAddress.implementsSerializable();
    }

    private static void topUser(Schema schema, String tableName) {
        Entity topUser = schema.addEntity(tableName);
        topUser.addStringProperty("avatar");
        topUser.addStringProperty("username");
        topUser.implementsSerializable();
    }

    /**
     * 静音
     */
    private static void messageStatus(Schema schema, String tableName) {
        Entity groupStatus = schema.addEntity(tableName);
        groupStatus.addStringProperty("username").primaryKey();
        groupStatus.implementsSerializable();
    }

    private static void groupMember(Schema schema, String tableName) {
        Entity groupMember = schema.addEntity(tableName);
        groupMember.addStringProperty("groupid");
        groupMember.addStringProperty("userid");
        groupMember.implementsSerializable();
    }

    private static void member(Schema schema, String tableName) {
        Entity member = schema.addEntity(tableName);
        member.addStringProperty("user_id");
        member.addStringProperty("nickname");
        member.addStringProperty("email");
        member.addStringProperty("cover");
        member.addStringProperty("status");
        member.addStringProperty("is_auth");
        member.addStringProperty("birthday");
        member.addStringProperty("true_name");
        member.addStringProperty("sign");
        member.addStringProperty("sex");
        member.addStringProperty("mobile");
        member.addStringProperty("vip_level");
        member.addStringProperty("unique_id");
        member.implementsSerializable();
    }

    private static void group(Schema schema, String tableName) {
        Entity group = schema.addEntity(tableName);
        group.addStringProperty("groupid").primaryKey();
        group.addStringProperty("cover");
        group.addStringProperty("groupname");
        group.implementsSerializable();
    }
}
